package reflect;

import reflect.annotations.AutoRunClass;

import java.io.File;

public class Test3 {
    public static void main(String[] args) throws Exception {
        File dir = new File(Test3.class.getResource(".").toURI());  

        String pname = Test3.class.getPackage().getName();
        File[] subs = dir.listFiles(f -> f.getName().endsWith(".class"));
        for(File sub :subs){
            String filename = sub.getName();
            String classname = filename.replaceAll(".class","");
            filename = pname+"."+classname;
            Class cls = Class.forName(filename);
            if(cls.isAnnotationPresent(AutoRunClass.class)){
                Object obj = cls.newInstance();
                System.out.println(obj);
            }
        }
    }
}
